﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DotNet.Business;
using DotNet.Model;
using DotNet.Common;

public partial class Admin_EditPageKey : System.Web.UI.Page
{
    pageSeoBll seoBll = new pageSeoBll();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["state"] != null)
            {
                string state = Request.QueryString["state"].ToString();
                switch (state.Trim())
                {
                    case "add":
                        add();
                        break;
                    case "edit":
                        EditPageSeo(Convert.ToInt32(Request.QueryString["id"]));
                        break;
                    default:
                        break;
                }
            }

        }

    }
    private void add()
    {
        pageSeo pSeo = new pageSeo();
        pSeo.Title = Request.Form["Title"].ToString();
        pSeo.pageKey = Request.Form["key1"].ToString() + "," + Request.Form["key2"].ToString() + "," + Request.Form["key3"].ToString() + "," + Request.Form["key4"].ToString() + "," + Request.Form["key5"].ToString() + "," + Request.Form["key6"].ToString();
        pSeo.Description = Request.Form["Description"].ToString();
        pSeo.pageTop = Request.Form["pageTop"].ToString();
        pSeo.Bottom = Request.Form["Bottom"].ToString();
        pSeo.pageName = Request.Form["pageName"].ToString();
        pSeo.fromPage = Request.Form["fromPage"].ToString();
        pSeo.pageSeoId = Convert.ToInt32(Request.Form["Hiddenid"].ToString());
        if (seoBll.Update(pSeo))
        {
            Response.Write("1");
            Response.End();
        }
    }
    public void EditPageSeo(int id)
    {
        pageSeo pSeo = seoBll.GetModel(id);
        this.fromPage.Value = pSeo.fromPage;
        this.pageTop.Value = pSeo.pageTop;
        this.Title.Value = pSeo.Title;

        string[] keys = pSeo.pageKey.Split(',');
        this.key1.Value= keys[0];
        this.key2.Value = keys[1];
        this.key3.Value = keys[2];
        this.key4.Value = keys[3];
        this.key5.Value = keys[4];
        this.key6.Value = keys[5];

        this.Description.Value = pSeo.Description;
        this.Bottom.Value = pSeo.Bottom;
        this.pageName.Value = pSeo.pageName;       
        this.Hiddenid.Value = id.ToString();
    }
    protected void fromPage_ServerChange(object sender, EventArgs e)
    {

    }
}
